<?php

class Control_SettingsController extends Zend_Controller_Action
{

    public function init()
    {
        $this->_helper->layout->setLayout('admin');
        $this->yesButton = 'Yes'; //напис на кнопці Так під час видалення
        $this->noButton = 'No'; //напис на кнопці Ні під час видалення
        $this->dbTable = new Control_Model_Table_Settings();
        $this->view->controller = $this->getRequest()->getControllerName();
        $this->view->action = $this->getRequest()->getActionName();
    }

    public function indexAction()
    {
        $this->_helper->redirector('edit');
    }

    public function editAction()
    {
        $this->view->PortfolioData = $this->dbTable->getAll();
        $form = new Control_Model_Form_Settings();
        $form->submit->setLabel('Update');
        $this->view->form = $form;
        $delparam = $this->_getParam('del', 0);

        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $day_quote = $form->getValue('day_quote');
                $advertise_link = $form->getValue('advertise_link');
                $advertise_img = $form->getValue('advertise_img');
                $copyright = $form->getValue('copyright');
                $this->dbTable->updateSettings($day_quote, $advertise_link, $advertise_img, $copyright);
                $this->_helper->redirector('edit');
            }
        } else {//Виведення сторінки едіт
            $avertise=$this->dbTable->getAdvertise();
            $aboutData['day_quote'] = $this->dbTable->getDayQuote();
            $aboutData['advertise_link'] = $avertise['res'];
            $aboutData['advertise_img'] = $avertise['params'];
            $aboutData['copyright'] = $this->dbTable->getCopyright();
            $form->populate($aboutData);
        }
    }


}



